We will take a look at ggspavis and the
SpatialExperiment object in Bioconductor.
library(zellkonverter)
library(SpatialExperiment)
library(ggspavis)
library(stardust)
library(RColorBrewer)
Let’s read it and convert it with zellkonverter
path_adata <- "/Users/giovanni.palla/Datasets/advomics_data_spatial"
ad <- readH5AD(paste0(path_adata,"/V10F24-105_A1_stereoscope.h5ad"))
Warning: The names of these selected uns$spatial items have been modified to match R conventions: 'V10F24-105_A1' ->
'V10F24.105_A1'Warning: The names of these selected uns items have been modified to match R conventions: '_scvi_manager_uuid' ->
'X_scvi_manager_uuid' and '_scvi_uuid' -> 'X_scvi_uuid'Warning: The names of these selected obs columns have been modified to match R conventions: '_indices' -> 'X_indices',
'ELF3_AGBL2 positive cells' -> 'ELF3_AGBL2.positive.cells', 'Endocardial cells' -> 'Endocardial.cells', 'Epicardial
fat cells' -> 'Epicardial.fat.cells', 'Lymphatic endothelial cells' -> 'Lymphatic.endothelial.cells', 'Lymphoid
cells' -> 'Lymphoid.cells', 'Myeloid cells' -> 'Myeloid.cells', 'SATB2_LRRC7 positive cells' ->
'SATB2_LRRC7.positive.cells', 'Schwann cells' -> 'Schwann.cells', 'Smooth muscle cells' -> 'Smooth.muscle.cells',
'Stromal cells' -> 'Stromal.cells', 'Vascular endothelial cells' -> 'Vascular.endothelial.cells', and 'Visceral
neurons' -> 'Visceral.neurons'
Look at the SpatialExperimentObject
coords <- as.matrix(reducedDim(ad, "spatial"))
colnames(coords) = c("x","y")
spe <- SpatialExperiment(
assay = assay(ad,"X"),
colData = ad@colData,
spatialCoords = coords,
)
spe[["sample_id"]] <- "V10F24-105_A1"
spe
class: SpatialExperiment
dim: 502 2169
metadata(0):
assays(1): ''
rownames(502): A2M ABCA9 ... ZNF385D ZNF468
rowData names(0):
colnames(2169): AAACAATCTACTAGCA-1 AAACAGAGCGACTCCT-1 ... TTGTTTCACATCCAGG-1 TTGTTTGTGTAAATTC-1
colData names(20): in_tissue array_row ... Visceral.neurons sample_id
reducedDimNames(0):
mainExpName: NULL
altExpNames(0):
spatialCoords names(2) : x y
imgData names(1): sample_id
path_img <- "./V10F24-105_A1.png"
spe <- addImg(spe,
sample_id = "V10F24-105_A1",
image_id = "V10F24-105_A1",
imageSource = path_img,
scaleFactor = 0.04155585,
load = TRUE)
colData(spe)
DataFrame with 2169 rows and 20 columns
in_tissue array_row array_col leiden X_indices Cardiomyocytes ELF3_AGBL2.positive.cells
<numeric> <numeric> <numeric> <factor> <numeric> <numeric> <numeric>
AAACAATCTACTAGCA-1 1 3 43 4 0 1.73613e-06 2.63602e-06
AAACAGAGCGACTCCT-1 1 14 94 5 1 4.65527e-01 1.11768e-04
AAACCGGGTAGGTACC-1 1 42 28 8 2 5.07666e-01 9.17303e-02
AAACCGTTCGTCCAGG-1 1 52 42 0 3 1.29556e-02 4.75903e-02
AAACCTAAGCAGCCGG-1 1 65 83 4 4 1.22499e-06 3.30878e-06
... ... ... ... ... ... ... ...
TTGTGTATGCCACCAA-1 1 56 60 3 2164 2.21985e-01 1.20458e-05
TTGTGTTTCCCGAAAG-1 1 51 59 3 2165 7.42314e-02 1.36711e-02
TTGTTCAGTGTGCTAC-1 1 24 64 1 2166 2.02858e-01 8.77654e-06
TTGTTTCACATCCAGG-1 1 58 42 0 2167 5.49917e-02 1.71335e-04
TTGTTTGTGTAAATTC-1 1 7 51 4 2168 3.68276e-05 6.57713e-06
Endocardial.cells Epicardial.fat.cells Lymphatic.endothelial.cells Lymphoid.cells Megakaryocytes
<numeric> <numeric> <numeric> <numeric> <numeric>
AAACAATCTACTAGCA-1 7.18265e-06 4.70958e-02 0.07174900 3.94957e-06 1.85054e-06
AAACAGAGCGACTCCT-1 1.35986e-01 3.82232e-02 0.00130384 1.25679e-01 4.31108e-05
AAACCGGGTAGGTACC-1 1.70480e-01 3.03219e-02 0.06204053 2.04559e-04 1.33041e-02
AAACCGTTCGTCCAGG-1 4.47221e-06 2.72076e-06 0.01039361 2.12998e-01 1.66399e-06
AAACCTAAGCAGCCGG-1 2.83412e-06 3.03445e-02 0.06675252 3.53437e-06 6.76978e-06
... ... ... ... ... ...
TTGTGTATGCCACCAA-1 1.73486e-01 7.52264e-02 3.45799e-02 1.23511e-01 2.97905e-02
TTGTGTTTCCCGAAAG-1 2.29955e-01 7.56451e-06 1.04336e-05 1.16271e-01 4.90569e-06
TTGTTCAGTGTGCTAC-1 7.66914e-05 4.79027e-06 1.54969e-02 1.82428e-01 6.98415e-06
TTGTTTCACATCCAGG-1 1.06166e-05 1.54471e-02 2.11418e-02 2.89142e-01 1.98310e-02
TTGTTTGTGTAAATTC-1 1.86435e-01 2.11039e-02 4.57555e-06 6.86577e-06 3.71163e-02
Myeloid.cells SATB2_LRRC7.positive.cells Schwann.cells Smooth.muscle.cells Stromal.cells
<numeric> <numeric> <numeric> <numeric> <numeric>
AAACAATCTACTAGCA-1 5.98324e-02 3.90242e-02 5.10024e-02 0.1125237 6.09225e-01
AAACAGAGCGACTCCT-1 1.38215e-02 4.57504e-02 1.05696e-01 0.0230188 1.05394e-05
AAACCGGGTAGGTACC-1 5.26261e-05 3.70224e-05 9.18031e-06 0.0192380 7.65207e-02
AAACCGTTCGTCCAGG-1 2.19633e-02 1.89110e-01 6.00117e-03 0.0444164 1.23533e-01
AAACCTAAGCAGCCGG-1 7.37372e-02 6.39107e-06 2.43021e-02 0.3608190 2.32163e-01
... ... ... ... ... ...
TTGTGTATGCCACCAA-1 4.02957e-02 0.0855837 8.27646e-06 2.00553e-02 0.1954228
TTGTGTTTCCCGAAAG-1 3.29083e-04 0.2335415 4.53491e-02 1.56497e-01 0.0928041
TTGTTCAGTGTGCTAC-1 1.13313e-01 0.0754649 8.12851e-06 7.34828e-06 0.2807275
TTGTTTCACATCCAGG-1 6.06932e-06 0.0422673 3.69965e-02 6.17583e-03 0.2398590
TTGTTTGTGTAAATTC-1 3.44671e-02 0.0748089 2.32609e-02 1.64804e-01 0.2895845
Vascular.endothelial.cells Visceral.neurons sample_id
<numeric> <numeric> <character>
AAACAATCTACTAGCA-1 2.41417e-06 0.00952812 V10F24-105_A1
AAACAGAGCGACTCCT-1 1.64129e-05 0.04481268 V10F24-105_A1
AAACCGGGTAGGTACC-1 5.69946e-03 0.02269486 V10F24-105_A1
AAACCGTTCGTCCAGG-1 1.64334e-01 0.16669481 V10F24-105_A1
AAACCTAAGCAGCCGG-1 1.24272e-01 0.08758564 V10F24-105_A1
... ... ... ...
TTGTGTATGCCACCAA-1 7.74797e-06 3.61712e-05 V10F24-105_A1
TTGTGTTTCCCGAAAG-1 3.73034e-02 2.40056e-05 V10F24-105_A1
TTGTTCAGTGTGCTAC-1 1.02289e-01 2.73095e-02 V10F24-105_A1
TTGTTTCACATCCAGG-1 1.55952e-01 1.18008e-01 V10F24-105_A1
TTGTTTGTGTAAATTC-1 1.27973e-01 4.03921e-02 V10F24-105_A1
plotSpots(spe,annotate = "Stromal.cells")
plotVisium(spe,fill = "array_row")
plotVisium(spe,fill = "Stromal.cells",)
countMatrix = as.data.frame(spe@assays@data@listData)
spotPositions = as.data.frame(spatialCoords(spe))
output <- weightStardust(
countMatrix = countMatrix, spotPositions = spotPositions,
spaceWeight = 0.75, pcaDimensions=10, res=0.8)
Computing nearest neighbor graph
Computing SNN
clusters_identities <- output@active.ident
Plot cluster identities
spe@colData$stardust_clusters <- clusters_identities
getPalette = colorRampPalette(brewer.pal(12, "Set1"))
Warning: n too large, allowed maximum for palette Set1 is 9
Returning the palette you asked for with that many colors
plotSpots(spe,annotate = "stardust_clusters",palette = getPalette(12), size=2)